#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution
// 
// Project : JackieHan.DotNet.Expression
// 
// File : AndAlsoModifier.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 修改表示And条件的表达式,将And改成Or
// 
// History : 
//			2010-10-22 11:41:48	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using System.Linq.Expressions;

#endregion

namespace JackieHan.DotNet.LinQExpression
{
    /// <summary> 
    /// 修改表示And条件的表达式,将And改成Or
    /// </summary>
    public class AndAlsoModifier:ExpressionVisitor
    {
        public Expression ModifyToOrElse(Expression expression)
        {
            return Visit(expression);
        }

        protected override Expression VisitBinary(BinaryExpression b)
        {
            if (b.NodeType == ExpressionType.AndAlso)
            {
                Expression left = this.Visit(b.Left);
                Expression right = this.Visit(b.Right);

                return Expression.MakeBinary(ExpressionType.OrElse, left, right, b.IsLiftedToNull, b.Method);
            }
            return base.VisitBinary(b);
        }
    }
}